<template>
  <div class="wrapper">
    index
    <router-link to="/" class="header">去home</router-link>
    <button @click="submitFn('ruleForm')">点击</button>
  </div>
</template>

<script lang="ts">
import {
  defineComponent,
  ref,
  reactive,
  computed,
  watch,
  getCurrentInstance,
  onMounted
} from "vue";
import { useRouter } from "vue-router";
import actions from "@/micro/actions";
export default defineComponent({
  name: "index",
  components: {},
  setup() {
    let state: any = reactive({
      ruleForm: {
        username: "admin",
        password: "admin"
      }
    });
    let aa=null
    // 挂载后生命周期
    onMounted(() => {
      console.log(2);
      // 注册一个观察者函数
      actions.onGlobalStateChange((state, prevState) => {
        console.log(state);
        aa=state.mainRouteLink
      }, true);
      // 最后一个参数是否立即执行一次
    });

    const router = useRouter();
    const submitFn = () => {
      console.log(actions);
      // aa('/')
      actions.setGlobalState({ a: "1" });
    };

    return {
      ...state,
      submitFn
    };
  }
});
</script>
<style>
.header{
  width: 10px;
}
</style>
<style scoped>
.app_content {
  background: #fff;
  padding: 20px;
  position: relative;
  padding-bottom: 30px;
}
</style>
